<?php
use yii\widgets\Pjax;
use yii\bootstrap\ActiveForm;

$disable = 'show_order';
if($model->member_id != yii::$app->user->identity->id){
	
	$disable = 'disable_order';
}

?>

<!-- ?php Pjax::begin(); ? -->
<?=  yii\web\View::registerCssFile("/css/magic-check.css",['depends' => 'app\assets\AppAsset']) ?>
<style type="text/css">
	.disable_order {
		width:100%;height:100%;line-height:200px;
		position:fixed;top:60px;left:0px; background:#CCC;z-index:9999;  
		filter:alpha(opacity=50); -moz-opacity:0.5;  -khtml-opacity: 0.5; opacity: 0.5; 
		text-align:center;font-size:24px;color:red;
	}

	.show_order { display:none;}
</style>

<h2 class="page-header">
	<small>
		<?= $model->product->name ?> - <?= $model->product->code ?> / 
		<?= $model->username ?> &nbsp;<?= $model->phone ?>
	</small>
</h2>
<input type="hidden" id="id" value="<?= $model->id?>">

<div id="" >
	<div class="<?= $disable ?>" >
		关联订单, 只有订单录入销售自己有权限操作!
	</div>
	
	<div class="col-md-6">
		<table class="table">
			<tr>
				<th>联系人</th>
				<th>联系电话</th>
				<th>订单号</th>
				<th>操作</th>
			<tr>
			<?php foreach($already as $order){ ?>
			<tr>
				<td><?= $order->username ?></td>
				<td><?= $order->phone ?></td>
				<td><?= $order->code ?></td>
				<td>
    	            <input class="magic-checkbox magic" type="checkbox"  checked id="room<?= $order->id?>" name="<?= $order->id?>">
    	           	<label for="room<?= $order->id ?>" title="取消关联">
						取消
					</label>
				</td>
			</tr>
			<?php } ?>
		</table>
	</div>
	<div class="col-md-6">
		<table class="table">
			<tr>
				<th>联系人</th>
				<th>联系电话</th>
				<th>订单号</th>
				<th>操作</th>
			<tr>
			<tr>
				<td colspan=4>
    			<?php $form = ActiveForm::begin(['method'=>'get']); ?>
					<input type="text" name="code" placeholder=" 订单号" value="<?= isset($params['code']) ? $params['code'] : ''?>" style="padding:3px;">
					<input type="text" name="username" placeholder=" 联系人" value="<?= isset($params['username']) ? $params['username'] : ''?>"  style="padding:3px;">
					<button type="submit" class="btn btn-info btn-sm">查询</button>
    			<?php ActiveForm::end(); ?>
				</td>
			<tr>
			<?php foreach($data as $order){ ?>
			<tr>
				<td><?= $order->username ?></td>
				<td><?= $order->phone ?></td>
				<td><?= $order->code ?></td>
				<td>
    	            <input class="magic-checkbox magic" type="checkbox" id="room<?= $order->id?>" name="<?= $order->id?>">
    	           	<label for="room<?= $order->id ?>" title="关联订单">
						选择
					</label>
				</td>
			</tr>
			<?php } ?>
		</table>

		<?= yii\widgets\LinkPager::widget(['pagination' => $pages]); ?>
	</div>
</div>

<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">
    $(".magic").click(function(){
        var parent_id  = $("#id").val(); // 获取主订单编号
        var child_id   = $(this).attr('name'); //  获取被绑定订单编号

        var checked = $(this).is(':checked');   // 是否选中
        
        $.get("/order/order/relation-save", {parent_id:parent_id, child_id:child_id,checked:checked}, function(data){
			console.log(data);
        });
    });

</script>
<?php app\components\JsBlock::end() ?>

<!-- ?php Pjax::end(); ? -->
